package com.baishancloud.log.common.entity

import scala.beans.BeanProperty
import scala.collection.mutable

/**
 * 用于缓存外部数据广播的对象
 *
 * @param domainInfo                域名信息缓存数据表
 * @param domainInfoFetch           是否获取域名信息，默认为false
 * @param account                   要获取那些账户下的域名，中间使用英文逗号分隔
 * @param accountDomainInfo         指定账户下的域名信息缓存数据表
 * @param accountDomainInfoFetch    是否获取指定账户下的域名信息，默认为false，如果设置为true，需要同时设置 <b>account</b> 参数值
 * @param serverCacheGroupInfo      服务端cache组信息缓存数据表
 * @param serverCacheGroupInfoFetch 是否获取服务端cache组信息，默认为false
 * @param countryInfo               国家信息缓存数据表
 * @param countryInfoFetch          是否获取国家信息，默认为false
 * @param provinceInfo              省份信息缓存数据表
 * @param provinceInfoFetch         是否获取省份信息，默认为false
 * @param ispInfo                   运营商信息缓存数据表
 * @param ispInfoFetch              是否获取运营商信息，默认为false
 * @param userInfo                  用户信息缓存数据表
 * @param userInfoFetch             是否获取用户信息，默认为false
 * @param nodeInfo                  主机对应节点和cache组信息缓存数据表
 * @param nodeInfoFetch             是否获取主机对应节点和cache组信息，默认为false
 * @param typeModuleInfo            主机对应typeModule信息缓存数据表
 * @param typeModuleInfoFetch       是否获取主机对应typeModule信息，默认为false
 * @param serviceTypeInfo           主机对应服务类型信息缓存数据表
 * @param serviceTypeInfoFetch      是否获取主机对应服务类型信息，默认为false
 * @param svgInfo                   主机对应SVG信息缓存数据表
 * @param svgInfoFetch              是否获取主机对应SVG信息，默认为false
 * @author ziqiang.wang
 * @date 2022/2/21 15:25
 */
case class ExternalDataEntity(
                               @BeanProperty var domainInfo: mutable.Map[String, DomainEntity] = mutable.Map[String, DomainEntity](),
                               @BeanProperty var domainInfoFetch: Boolean = false,
                               @BeanProperty var account: String = "",
                               @BeanProperty var accountDomainInfo: mutable.Map[String, DomainEntity] = mutable.Map[String, DomainEntity](),
                               @BeanProperty var accountDomainInfoFetch: Boolean = false,
                               @BeanProperty var serverCacheGroupInfo: mutable.Map[String, ServerCacheGroupEntity] = mutable.Map[String, ServerCacheGroupEntity](),
                               @BeanProperty var serverCacheGroupInfoFetch: Boolean = false,
                               @BeanProperty var countryInfo: mutable.Map[String, CountryEntity] = mutable.Map[String, CountryEntity](),
                               @BeanProperty var countryInfoFetch: Boolean = false,
                               @BeanProperty var provinceInfo: mutable.Map[String, ProvinceEntity] = mutable.Map[String, ProvinceEntity](),
                               @BeanProperty var provinceInfoFetch: Boolean = false,
                               @BeanProperty var ispInfo: mutable.Map[String, IspEntity] = mutable.Map[String, IspEntity](),
                               @BeanProperty var ispInfoFetch: Boolean = false,
                               @BeanProperty var userInfo: mutable.Map[String, Int] = mutable.Map[String, Int](),
                               @BeanProperty var userInfoFetch: Boolean = false,
                               @BeanProperty var nodeInfo: mutable.Map[String, NodeEntity] = mutable.Map[String, NodeEntity](),
                               @BeanProperty var nodeInfoFetch: Boolean = false,
                               @BeanProperty var typeModuleInfo: mutable.Map[String, mutable.Set[Int]] = mutable.Map[String, mutable.Set[Int]](),
                               @BeanProperty var typeModuleInfoFetch: Boolean = false,
                               @BeanProperty var serviceTypeInfo: mutable.Map[String, Byte] = mutable.Map[String, Byte](),
                               @BeanProperty var serviceTypeInfoFetch: Boolean = false,
                               @BeanProperty var svgInfo: mutable.Map[String, String] = mutable.Map[String, String](),
                               @BeanProperty var svgInfoFetch: Boolean = false
                             ) extends Serializable {

}

object ExternalDataEntity extends Serializable {
  def apply(): ExternalDataEntity = new ExternalDataEntity()

  /**
   * 获取外部缓存数据进行广播对象的默认对象，所有外部对象获取的开关均为false
   */
  val DEFAULT: ExternalDataEntity = new ExternalDataEntity()

  class Builder extends Serializable {
    private val inner = ExternalDataEntity.DEFAULT

    def enableDomainInfoFetch(): Builder = {
      inner.setDomainInfoFetch(true)
      this
    }

    /**
     * @param account 要获取那些账户下的域名，中间使用英文逗号分隔
     */
    def enableAccountDomainInfo(account: String): Builder = {
      inner.setAccount(account)
      inner.setAccountDomainInfoFetch(true)
      this
    }

    def enableServerCacheGroupInfo(): Builder = {
      inner.setServerCacheGroupInfoFetch(true)
      this
    }

    def enableCountryInfoFetch(): Builder = {
      inner.setCountryInfoFetch(true)
      this
    }

    def enableProvinceInfoFetch(): Builder = {
      inner.setProvinceInfoFetch(true)
      this
    }

    def enableIspInfoFetch(): Builder = {
      inner.setIspInfoFetch(true)
      this
    }

    def enableNodeInfoFetch(): Builder = {
      inner.setNodeInfoFetch(true)
      this
    }

    def enableTypeModuleInfoFetch(): Builder = {
      inner.setTypeModuleInfoFetch(true)
      this
    }

    def enableServiceTypeInfoFetch(): Builder = {
      inner.setServiceTypeInfoFetch(true)
      this
    }

    def enableSvgInfoFetch(): Builder = {
      inner.setSvgInfoFetch(true)
      this
    }

    def build(): ExternalDataEntity = {
      inner
    }

  }

  object Builder extends Serializable {
    def apply(): Builder = new Builder()
  }

}
